<%--
  Created by IntelliJ IDEA.
  User: hanfei
  Date: 18/7/25
  Time: 下午2:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.wuming.house.security.SecurityHander" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>活动管理</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/icon.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css">
    <style>
        .layui-table-cell{
            max-height: 150px;
        }
        img{
            width: 114px;
            height: 86px;
        }
    </style>
</head>
<body style="background-color: #f0f2f5;" class="childrenBody">
<div class="layui-fluid wuli-main">
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>活动管理</legend>
        </fieldset>
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label wuli-width-auto">标题</label>

                    <div class="layui-input-block wuli-margin-left wuli-width">
                        <input type="text" name="title" lay-verify="title" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label wuli-width-auto">活动来源</label>

                    <div class="layui-input-block wuli-margin-left wuli-width">
                        <input type="text" name="source" lay-verify="source" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-row wuli-button">
        <button id="btnSave" type="button" class="layui-btn layui-btn-normal">添加活动</button>
        <button id="btnQuery" type="button" class="layui-btn layui-btn-normal">查询搜索</button>
        <%--<button id="btnExport" type="button" class="layui-btn layui-btn-normal">导出表单</button>--%>
    </div>
    <div class="layui-row">
        <table class="layui-hide" id="reportInfo" lay-data="{height: 'full-200'}" lay-filter="reportinfo"></table>
        <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    </div>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">编辑</a>
    <%--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>--%>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${allServerPath}static/layui/layui/layui.js"></script>
<script type="text/html" id="imageTpl">
    <img src="${allServerPath}/upload/{{d.imagePath}}"/>
</script>
<script>
    layui.use(['form', 'laydate', 'table'], function () {
        var table = layui.table,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$;

        //监听工具条
        table.on('tool(reportinfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: '编辑活动',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['500px', '487px'],
                    content: '${allServerPath}web/activity/toEditActivity/2/' + data.id + '.htmls',
                    end: function () {
                        table.reload('reportContent', {
                        });
                    }
                });
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                            url: '${allServerPath}web/activity/delete/' + data.id + ".htmls",
                            method: 'get',
                            dataType: 'json',
                            success: function (result) {
                                if (result.success) {
                                    obj.del();
                                    layer.close(index);
                                }
                            },
                            error: function () {
                                layer.msg('删除失败,请稍后重试.');
                            }
                        }
                    );
                });
            }
        });

        table.render({
            elem: '#reportInfo'
            , url: '${allServerPath}web/activity/list.htmls?t=' + Date.parse(new Date())
            , cols: [[
                {type: 'checkbox'}
                , {field: 'id', width: 80, align: 'center', title: 'ID'}
                , {field: 'title', width: 300, align: 'center', title: '标题'}
                , {field: 'url', width: 220, align: 'center', title: '活动路径'}
                , {field: 'imagePath', width: 150, align: 'center', title: '活动图片',templet:'#imageTpl'}
                , {field: 'source', width: 140, align: 'center', title: '活动来源'}
                , {title: '操作', width: 200, align: 'center', toolbar: '#barDemo'}
            ]],
            id: 'reportContent',
            where: {
                "pId": 0
            }, //如果无需传递额外参数，可不加该参数
            method: 'get', //如果无需自定义HTTP类型，可不加该参数
            page: true,
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize'
            }, //如果无需自定义请求参数，可不加该参数
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'message' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }, //如果无需自定义数据响应名称，可不加该参数
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            },
            text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });

        $("#btnQuery").click(function () {
            var title = $("input[name='title']").val();
            var source = $("input[name='source']").val();
            table.reload('reportContent', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    "title": title,
                    "source":source
                }
            });
        });

        $("#btnSave").click(function () {
            layer.open({
                type: 2,
                title: '添加案例',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['500px', '487px'],
                content: '${allServerPath}web/activity/toEditActivity/1/0.htmls',
                end: function () {
                    table.reload('reportContent', {
                    });
                }
            });
        });
    });
</script>
</body>
</html>

